/**
 * This is the space port screen 
 * @author Nick Popescu, Andrew Darrohn
 */

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JButton;
import java.awt.Color;
import java.awt.Font;

import javax.swing.JLabel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 * @version 1.0  
 * @author Andrew Darrohn
 * makes thescreen 
 */
public class SpacePortScreen extends JPanel implements ActionListener {

    /**
     * jbutton
     */
    private final JButton btnBuyFuel;
    
    /**
     * slider
     */
    private final JSlider fuelSlider;
    
    /**
     * title
     */
    private final JLabel title;
    
    /**
     * fuel title
     */
    private final JLabel fuelTitle;
    
    /**
     * label for fuel amount
     */
    private final JLabel fuelAmountLabel;

    /**
     * Create the panel.
     */
    public SpacePortScreen() { // $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.constructorsOnlyInvokeFinalMethods
	setLayout(null);
	setOpaque(false);

	title = new JLabel();
	title.setText("Shipyard");
	title.setForeground(Color.WHITE);
	title.setBounds(10, 10, 150, 20); // $codepro.audit.disable numericLiterals
	title.setFont(new Font("Dialog", 1, 18)); // $codepro.audit.disable numericLiterals
	add(title);

	fuelTitle = new JLabel();
	fuelTitle.setText("Purchase Fuel");
	fuelTitle.setForeground(Color.WHITE);
	fuelTitle.setBounds(92, 50, 150, 20); // $codepro.audit.disable
	fuelTitle.setFont(new Font("Dialog", 1, 14)); // $codepro.audit.disable
	add(fuelTitle);

	fuelSlider = new JSlider();
	fuelSlider.setBackground(Color.GRAY);
	fuelSlider.setValue(100); // $codepro.audit.disable
	fuelSlider.setBounds(92, 88, 103, 23); // $codepro.audit.disable
	fuelSlider.addChangeListener(new ChangeListener() {

	    @Override
	    public void stateChanged(ChangeEvent e) {
		fuelAmountLabel
			.setText("# of Units: "
				+ (int) ((Game.Player.getShip() // $codepro.audit.disable 
					.getThisFuelSize() * ((double) fuelSlider
					.getValue() / fuelSlider.getMaximum())))
				+ "");
	    }
	});

	add(fuelSlider);

	btnBuyFuel = new JButton("Purchase");
	btnBuyFuel.setBounds(98, 110, 89, 23); // $codepro.audit.disable numericLiterals
	btnBuyFuel.addActionListener(this);
	add(btnBuyFuel);

	fuelAmountLabel = new JLabel(
		"# of Units: "
			+ (int) (Game.Player.getShip().getThisFuelSize() * ((double) fuelSlider // $codepro.audit.disable
				.getValue() / fuelSlider.getMaximum())) + "");
	fuelAmountLabel.setForeground(Color.WHITE);
	fuelAmountLabel.setBounds(97, 74, 150, 14); // $codepro.audit.disable numericLiterals
	add(fuelAmountLabel);

    }

    /**
     * action listener
     * @param e ActionEvent
     * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
     */
    @Override
    public void actionPerformed(ActionEvent e) {
	if (e.getSource().equals(btnBuyFuel)) {
	    System.out.println("Clicked Buy Fuel, with a slider value of"
		    + fuelSlider.getValue());

	    int fuelToAdd = (int) (Game.Player.getShip().getThisFuelSize() * ((double) fuelSlider // $codepro.audit.disable
		    .getValue() / fuelSlider.getMaximum()));
	    Game.Player.getCurrentPlanet().getSpacePort().fuelShip(fuelToAdd);

	}

    }
}
